//-----------------------------------------------------------------------
//<copyright file="DongMoKyBLL.cs
//Code gen by tool.
//</copyright>
//-----------------------------------------------------------------------
using System;
using PMS.Exceptions;
using System.Collections.Generic;
using PMS.DAL;
using PMS.Entity;
using System.Transactions;

namespace PMS.BLL
{
	public class DongMoKyBO : BaseBO
	{
		// Interface Instant Object
		private readonly IDongMoKyDAO dongmokyInterfaceObject = null;

		// Constructor
		public DongMoKyBO()
		{
			dongmokyInterfaceObject = new DAL.ServiceFactory<IDongMoKyDAO>().CurrentDAL;
		}

		#region DongMoKy

        /// <summary>
        ///
        /// </summary>
        /// <param name="dongmoky"></param>
        public bool DongKy(DongMoKy dongmoky)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    
                    dongmokyInterfaceObject.UpdateDongMoKy(dongmoky);
                    DongMoKy newKy = new DongMoKy();
                    newKy.NgayMoKy = dongmoky.NgayDongKy.AddDays(1);
                    newKy.NgayDongKy = newKy.NgayMoKy.AddMonths(1).AddDays(-1);
                    dongmokyInterfaceObject.CreateDongMoKy(newKy);
                    
                }
                catch (Exception ex)
                {
                    throw BusinessException.GetException("Business Access CreateDongMoKy Exception", ex);
                }
                scope.Complete();
            }
            return true;
        }

		/// <summary>
		///
		/// </summary>
		/// <param name="dongmoky"></param>
		public DongMoKy CreateDongMoKy(DongMoKy dongmoky)
		{
			try
			{
				return dongmokyInterfaceObject.CreateDongMoKy(dongmoky);
			}
			catch (Exception ex)
			{
				throw BusinessException.GetException("Business Access CreateDongMoKy Exception", ex);
			}
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="dongmoky"></param>
		public void UpdateDongMoKy(DongMoKy dongmoky)
		{
			try
			{
				dongmokyInterfaceObject.UpdateDongMoKy(dongmoky);
			}
			catch (Exception ex)
			{
				throw BusinessException.GetException("Business Access UpdateDongMoKyException", ex);
			}
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="dongmoky"></param>
		public void DeleteDongMoKy(DongMoKy dongmoky)
		{
			try
			{
				dongmokyInterfaceObject.DeleteDongMoKy(dongmoky);
			}
			catch (Exception ex)
			{
				throw BusinessException.GetException("Business Access DeleteDongMoKyException", ex);
			}
		}

		/// <summary>
		///
		/// </summary>
		public DongMoKies GetAllDongMoKy()
		{
			try
			{
				return dongmokyInterfaceObject.GetAllDongMoKy();
			}
			catch (Exception ex)
			{
				throw BusinessException.GetException("Business Access GetAllDongMoKy Exception", ex);
			}
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="maKy"></param>
		public DongMoKy GetDongMoKyByID(string maKy)
		{
			try
			{
				return dongmokyInterfaceObject.GetDongMoKyByID(maKy);
			}
			catch (Exception ex)
			{
				throw BusinessException.GetException("Business Access GetDongMoKyBy ID Exception", ex);
			}
		}

		#endregion
	}
}
